<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>账号设置</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../css/homepage/userSetting.css" media="all"/>

</head>
<body>
    <div class="vessel-body">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">
                    基础信息
                </li>
                <li>
                    密码修改
                </li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">

                    <div class="vessel-form">
                        <form class="layui-form" action="javascript:;" lay-filter="user_form">
                            <div class="layui-input-block">
                                <div class="layui-input-inline">
                                    <label class="layui-form-label">用户工号:</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="userJobNumber"    disabled>
                                    </div>
                                </div>
                                <div class="layui-input-inline">
                                    <label class="layui-form-label">用户账号:</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="userAccount"  disabled>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-input-block">
                                <div class="layui-input-inline">
                                    <label class="layui-form-label">用户姓名:</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input"  name="userName" >
                                    </div>
                                </div>
                                <div class="layui-input-inline">
                                    <label class="layui-form-label">用户手机号:</label>
                                    <div class="layui-input-inline">
                                        <input class="layui-input" name="userPhone" >
                                    </div>
                                </div>
                            </div>
                            <div class="layui-input-block">
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">备注:</label>
                                    <div class="layui-input-block">
                                        <textarea name="userRemark" placeholder="请输入内容" class="vessel-textarea layui-textarea"></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-input-block">
                            <div class="layui-form-item">
                                <div class="vessel-send layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="userfromsent">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                            </div>
                        </form>

                    </div>

                </div>

                <div class="layui-tab-item">
                    <div class="vessel-form">
                    <form class="set-password layui-form" action="javascript:;">
                            <div class="layui-input-block">
                                <label class="layui-form-label">旧的密码:</label>
                                <div class="layui-input-inline">
                                    <input type="password" class="layui-input" name="oldpwd" required lay-verify="required" lay-reqtext="旧的密码不能为空"   >
                                </div>
                            </div>
                            <div class="layui-input-block">
                                <label class="layui-form-label">新的密码:</label>
                                <div class="layui-input-inline">
                                    <input type="password" class="layui-input" name="newpwda" required lay-verify="required"  lay-reqtext="新的密码不能为空">
                                </div>
                            </div>
                            <div class="layui-input-block">
                                <label class="layui-form-label">确认密码:</label>
                                <div class="layui-input-inline">
                                    <input type="password" class="layui-input" name="newpwdb" required lay-verify="required"  lay-reqtext="新的密码不能为空" >
                                </div>
                            </div>
                        <div class="layui-input-block">
                            <div class="layui-form-item">
                                <div class="vessel-send layui-input-block">
                                    <button class="layui-btn" lay-submit lay-filter="pwdsend">立即提交</button>
                                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                </div>
                            </div>
                        </div>
                    </form>
                    </div>
                </div>
            </div>
        </div>


    </div>
</body>
<script src="../../layui/layui.js"></script>
<script>
    layui.use(['form','element'],function (){
        var form = layui.form,
            element = layui.element,
            $ = layui.$
        ;
        //获取用户信息
        var user = JSON.parse(sessionStorage.getItem("user"))
        console.log(user)
        form.val("user_form",user)
        form.on('submit(userfromsent)',function (d){
            d.field.userId = user.userId //添加需要更改的序号
            $.post({
                url:'/homepage/uptUserInfo',
                data:d.field,
                dataType:'json',
                success:res=>{
                    if (res.state == 200){
                        layer.msg('更改信息成功')
                        sessionStorage.setItem("user",JSON.stringify(d.field))//更新信息
                    }else {
                        layer.msg('更改失败')
                    }
                }
            })
        })
        form.on('submit(pwdsend)',function (d){
            if(d.field.newpwda != d.field.newpwdb){
                layer.msg('两次密码输入不一样！！！')
                return false
            }
            d.field.userId = user.userId //添加需要更改的序号
            $.post({
                url:'/homepage/uptUserPwd',
                data:d.field,
                dataJson:'json',
                success:res=>{
                    console.log(res)
                    if(res.state == '200'){
                        layer.msg('密码修改成功')
                    }else{
                        layer.msg(res.msg)
                    }
                }
            })
        })
    })
</script>
</html>